//
//  LFaccountDetailViewController.m
//  LoveFruit
//
//  Created by 刘栋 on 16/9/24.
//  Copyright © 2016年 张令林. All rights reserved.
//

#import "LFaccountDetailViewController.h"

#import "LFCustomeViewController.h"
#import "LFAccountOrderStateViewController.h"
#import "LFAccountOrderDetailViewController.h"

@interface LFaccountDetailViewController ()

@property (nonatomic,weak) UIScrollView *scrollView;

@end

@implementation LFaccountDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setUpNavi];
    
    //创建一个下面的scrollView
    [self createMainView];
}

- (void)createMainView
{
    //最下面的视图
    
    UIView *belowView = [[UIView alloc] init];
    belowView.backgroundColor = [UIColor whiteColor];
    
    
    //设置边框
    belowView.layer.borderWidth = 1;
    
    belowView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    
    [self.view addSubview:belowView];
    
    //设置约束
    [belowView mas_makeConstraints:^(MASConstraintMaker *make) {
       
//        make.left.right.bottom.equalTo(self.view);
        make.left.equalTo(self.view).offset(-1);
        make.right.equalTo(self.view).offset(1);
        make.bottom.equalTo(self.view);
        make.height.offset(50);
        
    }];
    
    //在上面添加两个按钮分别是删除订单和再来一旦
    UIButton *deleBut =  [UIButton buttonLRWithImgName:nil title:@"删除订单" color:[UIColor lightGrayColor] forSize:14 target:self action:@selector(deleteClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [deleBut setTitleColor:[UIColor colorWithHex:0x747474] forState:UIControlStateNormal];
    
    [belowView addSubview:deleBut];
    
    [deleBut mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.offset(15);
        make.top.offset(10);
        make.width.offset(60);
        make.height.offset(30);
    }];
    
    
    UIButton *addBut =  [UIButton buttonLRWithImgName:nil title:@"再来一单" color:[UIColor colorWithHex:0x353d44] forSize:13 target:self action:@selector(addClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [addBut setBackgroundImage:[UIImage imageNamed:@"v2_my_avatar_bg"] forState:UIControlStateNormal];
    
    addBut.adjustsImageWhenHighlighted = NO;
    
    addBut.layer.cornerRadius = 5;
    addBut.layer.masksToBounds = YES;
    
    
    [belowView addSubview:addBut];
    
    [addBut mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.offset(-10);
        make.top.offset(10);
        make.width.offset(70);
        make.height.offset(30);
    }];

    
    
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
    
    scrollView.pagingEnabled = YES;
    [self.view addSubview:scrollView];
    self.scrollView = scrollView;
    
    scrollView.scrollEnabled = NO;
    
    //去掉水平和水质方向的滚动条
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    
    //设置可以滚动的范围**
    scrollView.contentSize = CGSizeMake(self.view.bounds.size.width*2, self.view.bounds.size.height - 50);
    
    //设置约束
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.bottom.equalTo(belowView.mas_top);
    }];
    
    //给scrollView添加控制器
    LFAccountOrderStateViewController *stvc = [[LFAccountOrderStateViewController alloc] init];
    [self addChildViewController:stvc];
    
    [scrollView addSubview:stvc.view];
    
    LFAccountOrderDetailViewController *odvc = [[LFAccountOrderDetailViewController alloc] init];
    [self addChildViewController:odvc];
    
    [scrollView addSubview:odvc.view];
    
    //给控制器view添加约束
    [stvc.view mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.width.height.equalTo(self.scrollView);
        make.left.top.equalTo(self.scrollView);
    }];
    
    //
    [odvc.view mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.width.height.equalTo(self.scrollView);
        make.left.equalTo(stvc.view.mas_right);
        make.top.equalTo(self.scrollView);
    }];
}

//添加按钮
- (void)addClick:(UIButton *)but
{
    NSLog(@"添加按钮");
}

//删除按钮的点击
- (void)deleteClick:(UIButton *)but
{
    NSLog(@"删除按钮被点击了");
}

- (void)leftClick
{
    NSLog(@"返回");
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setUpNavi
{
    //设置返回按钮
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btn_backItem"] style:UIBarButtonItemStylePlain target:self action:@selector(leftClick)];
    
    self.navigationItem.leftBarButtonItem = leftItem;
    
    //设置右边的在线客服
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"在线客服" style:UIBarButtonItemStylePlain target:self action: @selector(rightClick:)];

    [rightItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:[UIColor colorWithHex:0x999999]} forState:UIControlStateNormal];
    
    self.navigationItem.rightBarButtonItem = rightItem;
    
    
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"订单状态",@"订单详情"]];
    [segment addTarget:self action:@selector(segmentClick:) forControlEvents:
     UIControlEventValueChanged];
    
    segment.tintColor = [UIColor colorWithHex:0xffd600];
    
    //设置字体颜色
    [segment setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13],NSForegroundColorAttributeName:[UIColor colorWithHex:0x818181]} forState:UIControlStateNormal];
    [segment setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13],NSForegroundColorAttributeName:[UIColor colorWithHex:0x181400]} forState:UIControlStateSelected];
    
//    segment.backgroundColor = [UIColor whiteColor];
    segment.backgroundColor = [UIColor whiteColor];
    
    segment.selectedSegmentIndex = 0;
    
    self.navigationItem.titleView = segment;
}

- (void)segmentClick:(UISegmentedControl *)segment
{
    NSInteger selectIndex = segment.selectedSegmentIndex;
    
    self.scrollView.contentOffset = CGPointMake(self.view.bounds.size.width * selectIndex, 0);
}

- (void)buttonClick:(UIButton *)but
{
    NSLog(@"按钮被点击了");
}

- (void)rightClick:(UIBarButtonItem *)item
{
    NSLog(@"右边阿牛被点击了");
    LFCustomeViewController *cvc = [[LFCustomeViewController alloc] init];
    [self.navigationController pushViewController:cvc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
